import time
from selenium.webdriver.common.by import By


class Tools:
    def __init__(self, driver):
        # driver：浏览器，只在传递进来的浏览器操作
        self.driver = driver
        self.driver.maximize_window()
        self.driver.implicitly_wait(10)

    def visit(self, url):
        self.driver.get(url)
        time.sleep(1)

    # css定位
    def by_css(self, css):
        return self.driver.find_element(By.CSS_SELECTOR, css)

    # link_text定位
    def by_link(self, link):
        return self.driver.find_element(By.PARTIAL_LINK_TEXT, link)

    # 切换表单
    def switch(self, css):
        return self.driver.switch_to.frame(self.by_css(css))

    # d.switch_to.default_content()
    # 切出表单
    def switch_to(self):
        return self.driver.switch_to.default_content()

    def d_d(self):
        return self.driver

    # 关闭浏览器
    def quit(self):
        self.driver.quit()
